var indent_state = "0";
var group_no = getQst("group_no").trim();
var uid = sessionStorage.getItem("u_group_no");
/* 获取订单id */
var request = GetRequest();
var indent_no = request['indent_no'];
var prescription_id = request['prescription_id'];
$(function () {
	prescription_id = getQst("prescription_id").trim();
	var paramJson = {"actName": "GetIndentD","order_id":prescription_id, "utype": "5", "uid": uid, "rand": Math.random() };
	ajaxGet("http://zz.nxk520.com/nethosp/service/nethosp_action.ashx", paramJson, doOk);
	
	/* 快递选择 */
	$("#txt_logistics_name").picker({
		title: "请选择快递公司",
		cols: [
			{
				textAlign: 'center',
				values: ['顺丰速运', '申通快递', '圆通快递', '韵达快递', '百世汇通', '邮政EMS']
			}
		],
		onChange: function (p, v, dv) {
			console.log(p, v, dv);
		},
		onClose: function (p, v, d) {
			console.log("close");
		}
	});
});

/* 页面跳转 */
function goOrderDetails(){
	history.back();
}

//获取数据
function doOk(rstData) {
	var sum_price = 0, str_dd_dtl_html = "";
	if (rstData.list.length > 0 ) {
		//生成html片段
		var html = template("shopCourier",rstData);
		var container = document.getElementById("shop_courier");
		//将html片段渲染到界面中
		container.innerHTML = html;
	}
	else {
		//生成html片段
		var html = template("noData",rstData.rows);
		var container = document.getElementById("shop_courier");
		//将html片段渲染到界面中
		container.innerHTML = html;
	}
}

//标记发货
function actddfh() {
	var str_logistics_name = $("#txt_logistics_name").val();
	var str_logistics_no = $("#txt_logistics_no").val();
	var str_logistics_cost = $("#txt_logistics_cost").val();
	if (isSpace(str_logistics_name)) {
		$.alert("请选择快递名称！", "提示", function () { });
		return false;
	}
	if (isSpace(str_logistics_no)) {
		$.alert("请输入快递单号！", "提示", function () { });
		return false;
	}
	if (isSpace(str_logistics_cost)) {
		$.alert("请输入快递费用！", "提示", function () { });
		return false;
	}
	if (!isNumber(str_logistics_cost)) {
		$.alert("快递费用只能是数值！", "提示", function () { });
		return false;
	}
	
	var paramJson = {"actName": "DoSendDrug","order_id":prescription_id, "utype": "5", "uid": uid,  "logistics_name": str_logistics_name, "logistics_no": str_logistics_no, "logistics_cost": str_logistics_cost, "rand": Math.random() };
	ajaxGet("http://zz.nxk520.com/nethosp/service/nethosp_action.ashx", paramJson, doOk);
	
	function doOk(res){
		console.log(res);
		if (res.code == "1") {
			$.alert("订单发货成功", function () { actToPage("shop_courier.html?prescription_id=" + prescription_id + "&indent_no=" + indent_no); });
		}
		else {
			$.alert("订单发货异常，错误为：" + rstData.reMsg, "错误", function () { });
		}
	}
	/* var ajaxArgs = {
		async: true, isLoad: true, type: "post", url: cflz_service_url,
		data: { "actName": "actPharmacy", "actTag": "actDDFH", "prescription_id": indent_no, "logistics_name": str_logistics_name, "logistics_no": str_logistics_no, "logistics_cost": str_logistics_cost, "rand": Math.random() },
		说明：自取发药快递公司、快递单号为空、快递配送需填快递公司、快递单号
		参数："actName": "DoSendDrug","order_id":"订单号",
		"logistics_name":"快递公司","logistics_no":"快递单号"
		var paramJson = {"actName": "DoSendDrug","order_id":prescription_id, "utype": "5", "uid": 201000, "rand": Math.random() };
		ajaxGet("http://zz.nxk520.com/nethosp/service/nethosp_action.ashx", paramJson, doOk);
		succCallback: function (rstData) {
			if (rstData.rows.reCode == "1") {
				$.alert("订单发货成功", function () { actToPage("shop_order_details.html?prescription_id=" + prescription_id + "&indent_no=" + indent_no); });
			}
			else {
				$.alert("订单发货异常，错误为：" + rstData.reMsg, "错误", function () { });
			}
		},
		errorCallback: function (errorMsg) {
			$.alert("订单发货异常，错误为：" + errorMsg, "错误", function () { });
		}
	};
	$ajax(ajaxArgs); */
}

function isNumber(val) {
	var regPos = /^\d+(\.\d+)?$/; //非负浮点数
	var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
	if (regPos.test(val) || regNeg.test(val)) {
		return true;
	} else {
		return false;
	}
}

//返回列表
function ToPage() {
	actToPage('shop_list1.htm?group_no=' + group_no);
}